package com.example.fontposition.dao.persest.repository.impl;

import cn.tedu.common.enumerator.ServiceCode;
import cn.tedu.common.ex.ServiceException;
import cn.tedu.common.pojo.vo.PageData;
import cn.tedu.common.util.PageInfoToPageDataConverter;
import cn.tedu.zhaopin.protocol.position.vo.PositionSimpleVO;
import com.example.fontposition.dao.persest.mapper.PositionMapper;
import com.example.fontposition.dao.search.IPositionESRepository;
import com.example.fontposition.dao.persest.repository.IPositionRepository;
import com.example.fontposition.pojo.po.PositionPO;
import com.example.fontposition.pojo.vo.PositionVO;
import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Repository;

import java.util.List;

@Repository
@Slf4j
public class PositionRepositoryImpl implements IPositionRepository {

    @Autowired
    private PositionMapper positionMapper;

    @Autowired
    private IPositionESRepository positionESRepository;

    @Override
    public PositionVO getStandardById(Long userId) {
        log.debug("开始执行【根据ID查询商品信息】的数据访问，参数：{}", userId);
        if (userId==null){
            String message = "查询商品失败，商品数据不存在！";
            log.warn(message);
            throw new ServiceException(ServiceCode.ERROR_NOT_FOUND, message);
        }
        return positionMapper.getStandardById(userId);
    }

    @Override
    public PageData<PositionSimpleVO> search(Integer pageNum, Integer pageSize) {
        PageHelper.startPage(pageNum,pageSize);
        List<PositionSimpleVO> list = positionMapper.list();
        PageInfo<PositionSimpleVO> pageInfo=new PageInfo<>(list);
        return PageInfoToPageDataConverter.convert(pageInfo);
    }


}
